<template>
  <view style="padding-bottom: 20rpx">
    <view class="" style="padding: 26rpx 38rpx; background-color: #fff4dd; color: #ffad00">
      温馨提示：急性病以当下状况为准，慢性病已近3天症状为 准，请认真填写以便医生准确诊疗。
    </view>
    <view class="" style="padding: 30rpx 28rpx">
      <view class="bg-white radius14 margin-bottom-sm" style="padding: 36rpx" v-for="(item, index) in list" :key="index">
        <view class="font26 col-666">第{{ index + 1 }}题 · {{ item.type == 1 ? '单选题' : item.type == 2 ? '多选题' : '问答题' }}</view>
        <view class="col-333" style="margin-top: 30rpx">
          {{ item.title }}
        </view>
        <view v-if="item.type == 1" class="flex align-center flex-wrap" style="margin-top: 34rpx; border-bottom: solid 1rpx #e8e8e8; padding-bottom: 9rpx">
          <view @click="setdx(index, item1)" class="margin-bottom flex align-center" style="width: 50%" v-for="(item1, index1) in item.select" :key="index1">
            <radio :checked="item.check == item1" style="transform: scale(0.6)"></radio>
            <view class="" style="padding-left: 13rpx">
              {{ item1 }}
            </view>
          </view>
        </view>
        <view v-if="item.type == 2 && item.check" class="flex align-center flex-wrap" style="margin-top: 34rpx; border-bottom: solid 1rpx #e8e8e8; padding-bottom: 9rpx">
          <view @click="change(index, item1)" class="margin-bottom flex align-center" style="width: 50%" v-for="(item1, index1) in item.select" :key="index1">
            <radio :checked="rSelect.indexOf(item1) != -1" style="transform: scale(0.6)"></radio>

            <view class="" style="padding-left: 13rpx">
              {{ item1 }}
            </view>
          </view>
        </view>
        <view v-if="item.type == 3" style="margin-top: 34rpx; border-bottom: solid 1rpx #e8e8e8; padding-bottom: 45rpx">
          <view class="flex-sub" style="background-color: #f8f8f8; padding: 26rpx 27rpx; border-radius: 14rpx">
            <textarea v-model="item.check" name="" id="" cols="30" rows="10" class="w-all" :placeholder="item.placeholder" placeholder-class="placestype"></textarea>
          </view>
        </view>
      </view>
    </view>

    <view v-if="id" class="flex align-center justify-center margin-bottom" style="margin-top: 118rpx">
      <view @click="submit" class="btnbg font30" style="width: 500rpx; height: 80rpx">提交</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      id: null,
      orderid: 1,
      list: [],
      rSelect: []
    };
  },
  onLoad(op) {
    console.log(op);
    op.id ? (this.id = op.id) : '';
    op.orderid ? (this.orderid = op.orderid) : '';
  },
  onShow() {
    if (this.id) {
      this.getlist();
    } else {
      this.getinfo();
    }
  },
  methods: {
    setdx(e, v) {
      this.list[e].check = v;
      console.log(v);
      this.$forceUpdate();
    },
    change(e, v) {
      if (this.rSelect.indexOf(v) != -1) {
        console.log('那个');
        this.rSelect.splice(this.rSelect.indexOf(v), 1);
        this.list[e].check.splice(this.list[e].check.indexOf(v), 1);
      } else {
        console.log('这个');
        this.rSelect.push(v);
        this.list[e].check.push(v);
        // e.push(v)
      }
      console.log(this.rSelect);
    },
    getisok(e, v) {
      console.log();
      return e.indexOf(v) != -1;
    },
    getlist() {
      this.util
        .request(
          '/template/consultDetails',
          {
            consult_id: this.id
          },
          'post'
        )
        .then((res) => {
          this.list = JSON.parse(res.record);
          console.log(this.list);
          for (let i = 0; i < this.list.length; i++) {
            if (this.list[i].type == 2) {
              this.list[i].check = [];
            } else {
              this.list[i].check = '';
            }
          }
        });
    },
    getinfo() {
      this.util
        .request(
          '/order/inquiryDetails',
          {
            order_id: this.orderid
          },
          'post'
        )
        .then((res) => {
          this.list = JSON.parse(JSON.stringify(JSON.parse(res.serve.inquiry_data)));
        });
    },
    submit() {
      // console.log(this.list)
      this.util
        .request(
          '/order/writeInquiry',
          {
            order_id: this.orderid,
            inquiry_data: JSON.stringify(this.list)
          },
          'post'
        )
        .then((res) => {
          this.util.showToast('提交成功', true);
        });
    }
  }
};
</script>

<style>
page {
  background-color: #f8f8f8;
}
</style>
